%baseclass-preinclude AnalyzersExtra.h
%class-name Parser
%class-header Parser.h
%implementation-header Parser.ih
%parsefun-source Parser.cpp
%scanner Scanner.h

%baseclass-preinclude cmath 

%stype double

%token NUMBER, CMD_END, ID, IMPORT, FUNC, BTEXT
%left '-' '+'
%left '*' '/'
%left NEG
%right '^'

%%

input:
  // empty
  | input line
;

line:
  '\n'
  | exp CMD_END {
    std::cout << "\t\e[1;32m" << $1 << "\e[m" << std::endl;
  }
  | class CMD_END
  /*   | stmt */
  | error CMD_END
  | function CMD_END
  | import CMD_END
  | expLst CMD_END
  {
  qDebug() << "lst";
  stackExp->append(d_scanner.YYText() );}
;

expLst: exp | exp '\n' expLst | exp ';' expLst ;
  
exp: |
  NUMBER {
    // $1 = atof(d_scanner.YYText());
    std::cerr << "\e[1;36mgot number: " << d_scanner.YYText() << "\e[m" << std::endl;
    $$ = atof(d_scanner.YYText());
  }
  | exp '+' exp {
    $$ = $1 + $3;
  }
  | exp '-' exp {
    $$ = $1 - $3;
  }
  | exp '*' exp {
    $$ = $1 * $3;
  }
  | exp '/' exp {
    $$ = $1 / $3;
  }
  | '-' exp %prec NEG {
    $$ = -$2;
  }
  | exp '^' exp {
    $$ = 0; //pow($1, $3);
  }
  | '(' exp ')' {
    $$ = $2;
  } 
; 

class:
  ID  '{' exp '}' {
      //std::cerr << "\e[1;36mgot class: " << $1 << "\e[m" << std::endl;
      QString s = stack->back();
      qDebug() << s;
      instHld->getObject(s, s);
      $$ = 0;
  }
;

import:
 IMPORT ID {
    QString s = stack->back();
    qDebug()<<"--> import "<< s;
    loader->loadLib(s);
    $$ = 0;
    }
  ;

function:
    FUNC ID '(' ')' '{' expLst '}' {
        QString s = stack->back();
        QString se = stackExp->back();
        qDebug()<<"--> func "<< s;
        qDebug()<<"--> funBody "<< se;
        scriptEng->evaluate(se);
            $$ = 0;
    };
  /*stmt:
    exp
  ;*/
